
/**		
 * 
 *	uk.co.lmfm.guppy.view.MenuMediator
 *	
 *	@version 1.00 | Jan 13, 2010
 *	@author Justin Windle
 *  
 **/
 
package uk.co.lmfm.guppy.view 
{
	import uk.co.lmfm.guppy.application.enum.ApplicationConstants;
	import uk.co.lmfm.guppy.view.components.events.MenuButtonEvent;
	import uk.co.lmfm.guppy.view.components.menu.MenuView;

	import org.puremvc.as3.multicore.interfaces.IMediator;
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.patterns.mediator.Mediator;

	/**
	 * MenuMediator
	 */
	public class MenuMediator extends Mediator implements IMediator 
	{
		//	----------------------------------------------------------------
		//	CONSTANTS
		//	----------------------------------------------------------------

		public static const NAME : String = "MenuMediator";

		//	----------------------------------------------------------------
		//	CONSTRUCTOR
		//	----------------------------------------------------------------

		public function MenuMediator(viewComponent : MenuView)
		{
			super(NAME, viewComponent);
		}

		//	----------------------------------------------------------------
		//	PUBLIC METHODS
		//	----------------------------------------------------------------

		override public function onRegister() : void
		{
			super.onRegister();
			
			component.addEventListener(MenuButtonEvent.VIEW_SELECTED, onViewSelected);
			component.show();
		}

		override public function listNotificationInterests() : Array
		{
			return [
					ApplicationConstants.GOT_VIEW_DEFINITION,
					ApplicationConstants.CHECKOUT_COMPLETE,					ApplicationConstants.ENABLE_MENU,					ApplicationConstants.DISABLE_MENU
					];
		}

		override public function handleNotification(notification : INotification) : void
		{
			super.handleNotification(notification);
			
			var name : String = notification.getName();
			var body : Object = notification.getBody();
			
			switch(name)
			{
				case ApplicationConstants.GOT_VIEW_DEFINITION : 
				
					component.addView(body.name, body.label);
				
					break;
					
				case ApplicationConstants.CHECKOUT_COMPLETE :
				
					component.enabled = true;
				
					break;
					
				case ApplicationConstants.ENABLE_MENU :
				
					component.enabled = true;
				
					break;
					
				case ApplicationConstants.DISABLE_MENU :
				
					component.enabled = false;
				
					break;
			}
		}

		//	----------------------------------------------------------------
		//	EVENT HANDLERS
		//	----------------------------------------------------------------

		private function onViewSelected(event : MenuButtonEvent) : void
		{
			sendNotification(ApplicationConstants.CHANGE_VIEW, event.view);
		}

		//	----------------------------------------------------------------
		//	PUBLIC ACCESSORS
		//	----------------------------------------------------------------

		public function get component() : MenuView
		{
			return viewComponent as MenuView;
		}
	}
}
